/* GUI CONVERTED from ecincpr1.p (converter v1.76) Mon Jun 10 07:04:38 2002 */
/* ecincpr1.p - PCO INCORPORATION PROCESSOR (CONTINUED)                      */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/* $Revision: 1.18.1.17 $                                                         */
/*V8:ConvertMode=Report                                                      */
/* REVISION: 7.4      LAST EDIT: 10/15/93      MODIFIED BY: pma *H013*       */
/* REVISION: 7.4      LAST EDIT: 03/17/94      MODIFIED BY: pxd *FL60*       */
/* REVISION: 7.4      LAST EDIT: 06/02/95      MODIFIED BY: qzl *H0DR*       */
/* REVISION: 7.4      LAST EDIT: 12/30/95      MODIFIED BY: qzl *H0J1*       */
/* REVISION: 7.4      LAST EDIT: 01/24/96      MODIFIED BY: bcm *G1KV*       */
/* REVISION: 7.4      LAST EDIT: 04/08/96      MODIFIED BY: rvw *H0KB*       */
/* REVISION: 7.4      LAST EDIT: 05/16/96      MODIFIED BY: rvw *H0L2*       */
/* REVISION: 8.6      LAST EDIT: 06/13/96   MODIFIED BY: *K00C  Joe Gawel    */
/* REVISION: 8.6      LAST EDIT: 01/10/97   MODIFIED BY: *H0R5* Russ Witt    */
/* REVISION: 8.6      LAST EDIT: 02/27/97   MODIFIED BY: *K05X* Joe Gawel    */
/* REVISION: 8.6      LAST EDIT: 01/24/97   MODIFIED BY: *H0QG* Russ Witt    */
/* REVISION: 8.6      LAST EDIT: 03/14/97   MODIFIED BY: *K07L* Joe Gawel    */
/* REVISION: 8.6      LAST EDIT: 03/21/97   MODIFIED BY: *K088* Joe Gawel    */
/* REVISION: 8.6      LAST EDIT: 04/18/97   MODIFIED BY: *K0BX* Joe Gawel    */
/* REVISION: 8.6      LAST EDIT: 06/20/97   MODIFIED BY: *K0FC* Joe Gawel    */
/* REVISION: 8.6      LAST EDIT: 06/26/97   MODIFIED BY: *K0F4* Joe Gawel    */
/* REVISION: 8.6      LAST EDIT: 07/19/97   MODIFIED BY: *K0G3* Russ Witt    */
/* REVISION: 8.6      LAST EDIT: 08/13/97   MODIFIED BY: *K0H5* Joe Gawel    */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane         */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan        */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan        */
/* REVISION: 8.6E     LAST MODIFIED: 12/01/98   BY: *K1YC* Santhosh Nair     */
/* REVISION: 9.1      LAST MODIFIED: 06/10/99   BY: *K213* Jyoti Thatte      */
/* REVISION: 9.1      LAST MODIFIED: 08/17/99   BY: *J3KL* Jyoti Thatte      */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane  */
/* REVISION: 9.1      LAST MODIFIED: 04/12/00   BY: *N08H* Vandna Rohira     */
/* REVISION: 9.1      LAST MODIFIED: 05/11/00   BY: *K260* Sathish Kumar     */
/* REVISION: 9.1      LAST MODIFIED: 06/30/00   BY: *N0F0* Arul Victoria     */
/* REVISION: 9.1      LAST MODIFIED: 08/08/00   BY: *M0QY* Mark Christian    */
/* REVISION: 9.1      LAST MODIFIED: 08/14/00   BY: *N0KW* Jacolyn Neder     */
/* REVISION: 9.1      LAST MODIFIED: 08/17/00   BY: *N0M1* Dave Caveney      */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Old ECO marker removed, but no ECO header exists *K00C*                    */
/* Old ECO marker removed, but no ECO header exists *N12T*                    */
/* Revision: 1.18.1.15    BY: Hualin Zhong       DATE: 10/01/01  ECO: *N12T*  */
/* $Revision: 1.18.1.17 $    BY: Seema Tyagi          DATE: 05/15/02  ECO: *N1HW*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/*********************************************************/
/* NOTES:   1. Patch FL60 sets in_level to a value       */
/*             of 999999 when in_mstr is created or      */
/*             when any structure or network changes are */
/*             made that affect the low level codes.     */
/*          2. The in_levels are recalculated when MRP   */
/*             is run or can be resolved by running the  */
/*             mrllup.p utility program.                 */
/*********************************************************/


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE ecincpr1_p_5 "PCO Nbr"
/* MaxLen: Comment: */

&SCOPED-DEFINE ecincpr1_p_7 "ID"
/* MaxLen: Comment: */

&SCOPED-DEFINE ecincpr1_p_9 "Message"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

/*  THE INCLUDE FILES USED FOR THIS PATCH (ECRODEF.I, ECROGET.I    */
/*  AND ECROPUT.I) SHOULD BE REMOVED ONCE THE NEW FIELDS HAVE BEEN */
/*  ADDED TO THE ECD2_DET TABLE IN THE SCHEMA.                     */

{ecrodef.i}  /* ECD2_DET SIDEFILE DEFINITIONS */

define variable unknown_char        as   character initial ?      no-undo.
define variable nbr                 like ecm_nbr
                                         label {&ecincpr1_p_5}    no-undo.
define variable ecmid               like wo_lot
                                         label {&ecincpr1_p_7}    no-undo.
define variable dbase               like si_db                    no-undo.
define variable effdate             like ecm_eff_date             no-undo.
define variable dte_out             as   date                     no-undo.
define variable dec_out             as   integer                  no-undo.
define variable err_msg             like msg_nbr                  no-undo.
define variable msg                 as   character label {&ecincpr1_p_9}
                                         format "x(58)"           no-undo.
define variable ptstatus1           like pt_status                no-undo.
define variable ptstatus2           like pt_status                no-undo.
define variable batch_size          like bom_batch                no-undo.
define variable batch_um            like bom_batch_um             no-undo.
define variable um                  like pt_um                    no-undo.
define variable formula             like mfc_logical              no-undo.
define variable oldrecid            as   recid                    no-undo.
define variable conv                like ps_um_conv initial 1     no-undo.
define variable conflicts           as   logical                  no-undo.
define variable new-component-added as   logical                  no-undo.
define variable sv-comp             like ecd1_comp                no-undo.
define variable sv-op               like ecd2_op                  no-undo.
define variable sv-sequence         like ecd4_sequence            no-undo.
define variable l_msgdesc           like msg_desc  extent 3       no-undo.
define variable l_msg               as   character format "x(56)" no-undo.
define variable l_start_ps          as   character format "x(40)" no-undo.
define variable l_start_is          as   character format "x(58)" no-undo.
define variable l_ps_complete       as   character format "x(40)" no-undo.
define variable l_is_complete       as   character format "x(58)" no-undo.
define variable l_incorp_success    as   character format "x(52)" no-undo.
define variable l_incorp_unsuccess  as   character format "x(58)" no-undo.

define new shared variable ps_recno     as   recid.
define new shared variable new_site     like si_site.
define new shared variable ro_recno     as   recid.

define            buffer psmstr         for  ps_mstr.
define            buffer inmstr         for  in_mstr.
define            buffer rodet          for  ro_det.
define            buffer ipddet         for  ipd_det.
define            buffer ecm1           for  ecm_mstr.

define new shared stream hf.
define     shared stream prt.

define temp-table wk-table
   field wk-par                  like ecd1_par
   field wk-new-component-added  as   logical
   index wk-par is primary wk-par ascending.

FORM /*GUI*/ 
   ps_start_ecn format "x(30)"
   ps_end_ecn   format "x(30)"
with STREAM-IO /*GUI*/  frame hf1 width 80 attr-space.

/* Don't call setFrameLabels as the frame is not used for display */
/* It is a buffer causes "Array subscript 61 is out of range" error */

{mfoutnul.i &stream_name = "hf"}

FORM /*GUI*/ 
   nbr
   ecmid
   dbase
   ecm_title
   effdate
   msg
with STREAM-IO /*GUI*/  frame c width 132 down.

/* SET EXTERNAL LABELS */
setFrameLabels(frame c:handle).

/* PROGRESS ERROR HAD BEEN ENCOUNTERED  */
{pxmsg.i &MSGNUM=3575 &MSGBUFFER=l_msgdesc[1]}

/* ERROR DETECTED: COMPONENT            */
{pxmsg.i &MSGNUM=3574 &MSGBUFFER=l_msgdesc[2]}

/* ERROR DETECTED: OPERATION            */
{pxmsg.i &MSGNUM=3767 &MSGBUFFER=l_msgdesc[3]}

/* Start Product Structure: */
{pxmsg.i &MSGNUM=4176 &MSGBUFFER=l_start_ps
         &MSGARG1="getTermLabel(""PARENT"", 12)"}

/* Product Structure Complete: */
{pxmsg.i &MSGNUM=4178 &MSGBUFFER=l_ps_complete
         &MSGARG1="getTermLabel(""PARENT"", 12)"}

/* Incorporation Completed Successfully */
{pxmsg.i &MSGNUM=4184 &MSGBUFFER=l_incorp_success}

/* Incorporation Unsucessful.  No changes made. */
{pxmsg.i &MSGNUM=4185 &MSGBUFFER=l_incorp_unsuccess}

/*PROCESS CHANGES*/
mainloop:
for each ecm_mstr
   fields(ecm_doc_type ecm_eff_date ecm_nbr ecm_selected_eff ecm_title)
   where ecm_eff_date      = ?
     and ecm_selected_eff <> ?
   no-lock
   by ecm_selected_eff transaction with frame c:

   
/*GUI*/ {mfguichk.i  &warn=false &stream="(prt)"} /*Replace mfrpchk*/


   effdate = ecm_selected_eff.

   if effdate < today
   then
      effdate = today.

   display
      stream prt
      space(5)
      substring(ecm_nbr,1,8)  @ nbr
      substring(ecm_nbr,9,8)  @ ecmid
      substring(ecm_nbr,17,8) @ dbase
      ecm_title
      effdate
      getTermLabel("BEGIN_INCORPORATION", 58) @ msg
   with frame c STREAM-IO /*GUI*/ .
   down stream prt with frame c.

   err_msg = 0.

   begin-changes:
   do on error undo begin-changes, leave begin-changes:

      /* CLEAR TEMP TABLE USED TO STORE PARENT ITEMS FOR MRP UPDATE */
      for each wk-table exclusive-lock:
         delete wk-table.
      end.

      ecd1-loop2:
      for each ecd1_det
         fields(ecd1_batch_pct ecd1_comp ecd1_fcst_pct ecd1_group
                ecd1_item_no ecd1_lt_off ecd1_nbr ecd1_op ecd1_par
                ecd1_psprocess ecd1_qty_per_b ecd1_qty_type ecd1_ref
                ecd1_rmks ecd1_scrp_pct ecd1__qad01 ecd1__qad03
                ecd1__qad04 ecd1__qad05)
         where ecd1_nbr = ecm_nbr
         no-lock
         break by ecd1_nbr
               by ecd1_par with frame c:

         assign
            err_msg = 1
            sv-comp = ecd1_comp.

         
/*GUI*/ {mfguichk.i  &warn=false &stream="(prt)"} /*Replace mfrpchk*/


         /* PRINT 'STRUCTURE XXX START' MESSAGE IF FIRST-OF ECD1_DET */
         if first-of(ecd1_par)
         then do with frame c:
            display
               stream prt
               (l_start_ps + ecd1_par) @ msg
            with frame c STREAM-IO /*GUI*/ .
            down stream prt with frame c.

            new-component-added = no.
         end. /* IF FIRST-OF(ecd1_par) */

         if effdate = ?
         then do:
            /* EFFECTIVE DATE REQUIRED */
            err_msg = 8112.
            undo ecd1-loop2, leave.
         end.

         /*GROSS CYCLICAL CHECK*/
         if ecd1_par = ecd1_comp
         then do:
            /* CYCLIC PRODUCT STRUCTURE NOT ALLOWED */
            err_msg = 206.
            undo ecd1-loop2, leave.
         end.

         assign
            oldrecid  = ?
            ptstatus1 = ""
            ptstatus2 = ""
            um        = "".

         for first pt_mstr
            fields(pt_batch pt_bom_code pt_formula pt_part pt_pm_code
                   pt_status pt_um)
            where pt_part = ecd1_par
            no-lock:
         end. /* FOR FIRST pt_mstr */

         if available pt_mstr
         then
            assign
               pt_recno  = recid(pt_mstr)
               ptstatus1 = pt_status.

         for first pt_mstr
            fields(pt_batch pt_bom_code pt_formula pt_part pt_pm_code
                   pt_status pt_um)
            where pt_part = ecd1_comp
            no-lock:
         end. /* FOR FIRST pt_mstr */

         if available pt_mstr
         then
            assign
               ptstatus2 = pt_status
               um        = pt_um.
         else do:
            for first bom_mstr
               fields(bom_batch bom_batch_um bom_formula bom_mod_date
                      bom_parent bom_userid)
               where bom_parent = ecd1_comp
               no-lock:
            end. /* FOR FIRST bom_mstr */

            if available bom_mstr
            then
               um = bom_batch_um.
         end. /* ELSE DO */

         if not available pt_mstr
            and not available bom_mstr
         then do:
            /* ITEM NUMBER OR BOM CODE MUST EXIST */
            err_msg = 231.
            undo ecd1-loop2, leave.
         end.

         if can-find(pt_mstr
                        where pt_part = ecd1_par)
         then do:

            /*CHECK ITEM STATUS*/
            substring(ptstatus1,9,1) = "#".
            if can-find(isd_det
                           where isd_status  = ptstatus1
                             and isd_tr_type = "INC-PS")
            then do:
               /* RESTRICTED PROCEDURE FOR ITEM STATUS CODE */
               err_msg = 358.
               undo ecd1-loop2, leave.
            end. /* IF CAN-FIND (isd_det .. */

            if can-find(isd_det
                           where isd_status  = ptstatus1
                             and isd_tr_type = "ADD-PS")
            then do:
               /* RESTRICTED STATUS # FOR # */
               {pxmsg.i &MSGNUM    =4177
                        &ERRORLEVEL=2
                        &MSGARG1   ="""'ADD-PS'"""
                        &MSGARG2   =ecd1_par
                        &MSGBUFFER =l_msg}

               l_msg = " **" + l_msg.

               display stream prt
               l_msg @ msg WITH STREAM-IO /*GUI*/ .
               down stream prt 2 with frame c.
            end. /* IF CAN-FIND (isd_det .. */

          end. /* IF CAN-FIND(pt_mstr... */

         if can-find(pt_mstr
                        where pt_part = ecd1_comp)
         then do:

            substring(ptstatus2,9,1) = "#".
            if can-find(isd_det
                           where isd_status  = ptstatus2
                             and isd_tr_type = "INC-PS")
            then do:
               /* RESTRICTED PROCEDURE FOR ITEM STATUS CODE */
               err_msg = 358.
               undo ecd1-loop2, leave.
            end. /* IF CAN-FIND (isd_det .. */

            if can-find(isd_det
                           where isd_status  = ptstatus2
                             and isd_tr_type = "ADD-PS")
            then do:
               /* RESTRICTED STATUS # FOR # */
               {pxmsg.i &MSGNUM    =4177
                        &ERRORLEVEL=2
                        &MSGARG1   ="""'ADD-PS'"""
                        &MSGARG2   =ecd1_comp
                        &MSGBUFFER =l_msg}

               l_msg = " **" + l_msg.

               display stream prt
               l_msg @ msg WITH STREAM-IO /*GUI*/ .
               down stream prt 2 with frame c.
            end. /* IF CAN-FIND (isd_det .. */

         end. /* IF CAN-FIND(pt_mstr... */

         /* SEE IF PRODUCT STRUCTURE ALREADY EXISTS FOR THIS PAR AND COMP */
         /* AND THAT A NEW COMPONENT HASN'T ALREADY BEEN ADDED            */
         if new-component-added = no
         then do:
            if not can-find (first ps_mstr
                                where ps_par  = ecd1_par
                                  and ps_comp = ecd1_comp)
            then
               new-component-added = yes.
         end. /* if new component-added = no */

         /*DEACTIVATE EXISTING RECORD*/
         find first ps_mstr exclusive-lock
            where ps_par  = ecd1_par
              and ps_comp = ecd1_comp
              and ps_ref  = ecd1_ref
              and (   ps_start < effdate
                   or ps_start = ?)
              and (   ps_end   > effdate
                   or ps_end   = ?)
         no-error.

         if available ps_mstr
         then do:
            assign
               ps_end      = effdate - 1
               ps_end_ecn  = ecm_nbr
               oldrecid    = recid(ps_mstr)
               ps_mod_date = today.

            if batchrun
            then
               ps_userid = report_userid.
            else
               ps_userid = global_userid.
         end.   /* IF AVAILABLE ps_mstr */

         /*ADD NEW AND MODIFIED RECORDS*/
         if substring(ecm_doc_type,3) <> "R"
            and not ecd1__qad01
         then do:

            /*ADD BOM MASTER IF NECESSARY*/
            for first bom_mstr
               fields(bom_batch bom_batch_um bom_formula bom_mod_date
                      bom_parent bom_userid)
               where bom_parent = ecd1_par
               no-lock:
            end. /* FOR FIRST bom_mstr */

            if not available bom_mstr
            then do:
               for first pt_mstr
                  fields(pt_batch pt_bom_code pt_formula pt_part pt_pm_code
                         pt_status pt_um)
                  where recid(pt_mstr) = pt_recno
                  no-lock:
               end. /* FOR FIRST pt_mstr */

               create bom_mstr.
               assign
                  bom_parent   = ecd1_par
                  bom_mod_date = today
                  bom_batch_um = pt_um
                  bom_batch    = pt_batch
                  bom_formula  = pt_formula.

               if recid(bom_mstr) = -1 then .

               if batchrun
               then
                  bom_userid = report_userid.
               else
                  bom_userid = global_userid.
            end.   /* if not available bom_mstr */

            batch_size = bom_batch.

            if batch_size   <= 0
               or batch_size = ?
            then
               batch_size = 1.

            batch_um = bom_batch_um.

            /*CHECK THAT CONVERSION OK*/
            conv = 1.
            if um <> batch_um
               and (ecd1_qty_type = "P" or ecd1_qty_type = "B")
            then do:
               {gprun.i ""gpumcnv.p""
                  "(um, batch_um, ecd1_comp, output conv)"}

               if conv = ?
                  and ecd1_qty_type = "P"
               then do:
                  /* NO UNIT OF MEASURE CONVERSION EXISTS */
                  err_msg = 33.
                  undo ecd1-loop2, leave.
               end.  /* if conv = ?... */
            end.    /* if um <> batch_um.... */

            if conv = ?
               and ecd1_qty_type = "B"
            then
               conv = 0.

            /*CHECK FOR DUPLICATE PS_MSTR RECORD*/
            if can-find (ps_mstr
                            where ps_par   = ecd1_par
                              and ps_comp  = ecd1_comp
                              and ps_ref   = ecd1_ref
                              and ps_start = effdate)
            then do:
               /* DUPLICATE ENTRY FOR THIS DATE */
               err_msg = 5406.
               undo ecd1-loop2, leave.
            end. /* IF can-find(ps_mstr ... */

            /*CREATE NEW RECORD*/
            if oldrecid <> ?
            then do:
               for first ps_mstr
                  where recid(ps_mstr) = oldrecid
                  no-lock:
               end. /* FOR FIRST ps_mstr */

               display
                  stream hf
                  ps_mstr
               with frame hf STREAM-IO /*GUI*/ .
            end.   /* if oldrecid <> ?... */
            else do:
               display
                  stream hf
                  ecd1_par      @ ps_par
                  ecd1_comp     @ ps_comp
                  ecd1_ref      @ ps_ref
                  ecd1_qty_type @ ps_qty_type
               with frame hf STREAM-IO /*GUI*/ .
            end.  /* else do... */

            display
               stream hf
               effdate @ ps_start
               ""      @ ps_end_ecn
               ecm_nbr @ ps_start_ecn format "x(24)"
            with frame hf STREAM-IO /*GUI*/ .

            create ps_mstr.
            assign ps_mstr.

            if recid(ps_mstr) = -1 then .

            /* ASSIGNING PS_START_ECN EXPLICITLY DUE TO PADDED */
            /* SPACES IN ECM_NBR */
            assign
               ps_start_ecn = ecm_nbr
               ps_mod_date  = today.

            if batchrun
            then
               ps_userid = report_userid.
            else
               ps_userid = global_userid.

            ps_recno = recid(ps_mstr).

            /*CHECK FOR CYCLICAL STRUCTURES*/
            pause 0.
            {gprun.i ""bmpsmta.p""}

            if ps_recno = 0
            then do:
               /* CYCLIC PRODUCT STRUCTURES NOT ALLOWED */
               err_msg = 206.
               undo ecd1-loop2, leave.
            end.

            /*FIND END DATE FOR NEW RECORD*/
            do for psmstr:
               for first psmstr
                  where psmstr.ps_par        = ps_mstr.ps_par
                    and psmstr.ps_comp       = ps_mstr.ps_comp
                    and psmstr.ps_ref        = ps_mstr.ps_ref
                    and (    psmstr.ps_start > ps_mstr.ps_start
                         and psmstr.ps_start <> ?)
                  no-lock:
               end. /* FOR FIRST psmstr */

               if available psmstr
               then
                  ps_mstr.ps_end = psmstr.ps_start - 1.
               else
                  ps_mstr.ps_end = ?.

               find first psmstr
                  where psmstr.ps_par       = ps_mstr.ps_par
                    and psmstr.ps_comp      = ps_mstr.ps_comp
                    and psmstr.ps_ref       = ps_mstr.ps_ref
                    and (   psmstr.ps_start < ps_mstr.ps_start
                         or psmstr.ps_start = ?)
               exclusive-lock no-error.

               if available psmstr
                  and (   psmstr.ps_end  = ?
                       or psmstr.ps_end >= ps_mstr.ps_start)
               then
                  psmstr.ps_end = ps_mstr.ps_start - 1.
            end.  /* do for ps_mstr... */

            /*UPDATE QTY PER*/
            if ecd1_qty_type = ""
            then
               assign
                  ps_qty_per   = ecd1_qty_per_b
                  ps_qty_per_b = ecd1_qty_per_b
                  ps_batch_pct = 0.
            else if ecd1_qty_type = "B"
                    and batch_size <> 0
            then
               assign
                  ps_qty_per_b = ecd1_qty_per_b
                  ps_qty_per   = ecd1_qty_per_b / batch_size
                  ps_batch_pct = 0.

            else if ecd1_qty_type = "P"
                    and conv <> 0
            then
               assign
                  ps_batch_pct = ecd1_batch_pct
                  ps_qty_per_b = ecd1_batch_pct * .01 * batch_size / conv
                  ps_qty_per   = ecd1_qty_per_b / if batch_size = 0
                                                  then
                                                     1
                                                  else
                                                     batch_size.

            /*UPDATE REST OF RECORD*/
            assign
               ps_item_no  = ecd1_item_no
               ps_op       = ecd1_op
               ps_rmks     = ecd1_rmks
               ps_scrp_pct = ecd1_scrp_pct
               ps_ps_code  = ecd1__qad03.

            if ecd1__qad04    <> "0"
            then
               ps_mandatory = true.
            else
               ps_mandatory = false.

            if ecd1__qad05    <> "0"
            then
               ps_default   = true.
            else
               ps_default   = false.

            assign
               ps_lt_off   = ecd1_lt_off
               ps_fcst_pct = ecd1_fcst_pct
               ps_group    = ecd1_group
               ps_process  = ecd1_psprocess.

         end. /*if not substring(ecm_doc_type,3...*/

         err_msg = 0.

         /* SAVE PARENT IN TEMP TABLE FOR MRP USAGE LATER */
         if last-of(ecd1_par)
         then do:
            find first wk-table where wk-par = ecd1_par no-error.
            if not available wk-table
            then do:
               create wk-table.
               assign
                  wk-par                 = ecd1_par
                  wk-new-component-added = new-component-added.
            end.  /* IF NOT AVAILABLE WK-TABLE.... */
            else do:
               /* IF TEMP-TABLE ALREADY EXISTS, SET NEW COMPONENT FLAG  */
               /* IF THIS FLAG IS NOT ALREADY = YES, BECAUSE ANY        */
               /* PCO THAT ADDS A NEW COMPONENT SHOULD TRIGGER LOW      */
               /* LEVEL CODE UPDATE TO 99999 IN IN_MSTR                 */
               if wk-new-component-added = no
               then
                  wk-new-component-added = new-component-added.
            end.  /* IF AVAILABLE WK-TABLE...  */

            display
               stream prt
               (l_ps_complete + ecd1_par) @ msg
            with frame c STREAM-IO /*GUI*/ .
            down stream prt with frame c.
         end.  /* if last-of(ecd1_par)... */

      end. /*for each ecd1_det*/

      if err_msg <> 0
      then do:
         /* PRINT COMPONENT AND ERROR# */
         display
            stream prt
            (l_msgdesc[2] + " " + sv-comp) @ msg
         with frame c STREAM-IO /*GUI*/ .
         down stream prt with frame c.

         run print-error-description.

         undo begin-changes, leave begin-changes.
      end.  /* err_msg <> 0... */

      ecd2-loop2:
      for each ecd2_det
         fields(ecd2_cmtindx ecd2_desc ecd2_mch ecd2_mch_op ecd2_men_mch
                ecd2_nbr ecd2_op ecd2_routing ecd2_run ecd2_setup
                ecd2_setup_men ecd2_std_op ecd2_sub_cost ecd2_tool
                ecd2_vend ecd2_wkctr ecd2_yield_pct ecd2__qad01)
         where ecd2_nbr = ecm_nbr
         no-lock
         break by ecd2_nbr
               by ecd2_routing with frame c:

         assign
            err_msg = 1
            sv-op   = ecd2_op.

         
/*GUI*/ {mfguichk.i  &warn=false &stream="(prt)"} /*Replace mfrpchk*/


         /* PRINT 'ROUTING XXX START' MESSAGE IF FIRST ECD2_DET */
         if first-of(ecd2_routing)
         then do with frame c:
            display
               stream prt
               (getTermLabel("START_ROUTING", 38) + ": " + ecd2_routing) @ msg
            with frame c STREAM-IO /*GUI*/ .
            down stream prt with frame c.
         end. /* IF FIRST-OF(ecd2_routing) */

         {ecroget.i &nbr    =ecd2_nbr
                    &routing=ecd2_routing
                    &op     =ecd2_op
                    &lock   =no-lock}

         if effdate = ?
         then do:
            /* EFFECTIVE DATE REQUIRED */
            err_msg = 8112.
            undo ecd2-loop2, leave.
         end.

         /*DEACTIVATE EXISTING RECORD*/
         find first ro_det exclusive-lock
            where ro_routing   = ecd2_routing
              and ro_op        = ecd2_op
              and (   ro_start < effdate
                   or ro_start = ?)
              and (ro_end      > effdate
                   or ro_end   = ?)
         no-error.
         if available ro_det
         then do:
            assign
               ro_end      = effdate - 1
               ro_end_ecn  = ecm_nbr
               oldrecid    = recid(ro_det)
               ro_mod_date = today.

            if batchrun
            then
               ro_mod_userid = report_userid.
            else
               ro_mod_userid = global_userid.
         end.  /* if available ro_det... */
         else
            oldrecid = ?.

         /*ADD NEW AND MODIFIED RECORDS*/
         if substring(ecm_doc_type,3) <> "R"
            and not ecd2__qad01
         then do:

            /*CHECK FOR DUPLICATE ROUTING RECORD*/
            if can-find (ro_det
                            where ro_routing = ecd2_routing
                              and ro_op      = ecd2_op
                              and ro_start   = effdate)
            then do:
               /* DUPLICATE ENTRY FOR THIS DATE */
               err_msg = 5406.
               undo ecd2-loop2, leave.
            end.

            /*CREATE NEW RECORD*/
            if oldrecid <> ?
            then do:

               for first ro_det
                  where recid(ro_det) = oldrecid
                  no-lock:
               end. /* FOR FIRST ro_det */

               display
                  stream hf
                  ro_det
               with frame hf1 STREAM-IO /*GUI*/ .
            end.  /* if oldrecid <> ?... */
            else
               display
                  stream hf
                  ecd2_routing @ ro_routing
                  ecd2_op      @ ro_op
               with frame hf1 STREAM-IO /*GUI*/ .

            create ro_det.

            assign
               ro_routing   = ecd2_routing
               ro_op        = ecd2_op
               ro_start     = effdate
               ro_start_ecn = ecm_nbr
               ro_end_ecn   = ""
               ro_mod_date  = today.

            if recid(ro_det) = -1 then .

            if batchrun
            then
               ro_mod_userid = report_userid.
            else
               ro_mod_userid = global_userid.

            ro_recno = recid(ro_det).

            /*FIND END DATE FOR NEW RECORD*/
            do for rodet:
               for first rodet
                  where ro_routing  = ro_det.ro_routing
                    and ro_op       = ro_det.ro_op
                    and ro_bom_code = ro_det.ro_bom_code
                    and (ro_start   > ro_det.ro_start
                    and ro_start    <> ?)
                  no-lock:
               end. /* FOR FIRST rodet */

               if available rodet
               then
                  ro_det.ro_end = ro_start - 1.
               else
                  ro_det.ro_end = ?.

               find first rodet
                  where ro_routing   = ro_det.ro_routing
                    and ro_op        = ro_det.ro_op
                    and ro_bom_code  = ro_det.ro_bom_code
                    and (   ro_start < ro_det.ro_start
                         or ro_start = ?)
               exclusive-lock no-error.

               if available rodet
                  and (   ro_end  = ?
                       or ro_end >= ro_det.ro_start)
               then
                  ro_end = ro_det.ro_start - 1.
            end.  /* do for ro_det... */

            if (     ro_start <> ?
                and  ro_end   <> ?
                and (ro_start <= ro_end))
            then do:
               conflicts = false.

               for each rodet
                  no-lock
                  where ro_routing                  =  ro_det.ro_routing
                    and ro_op                       =  ro_det.ro_op
                    and recid(ro_det)               <> recid(rodet)
                    and (    (    rodet.ro_end      = ?
                              and ro_det.ro_end     = ?)
                         or  (    rodet.ro_start    = ?
                              and ro_det.ro_start   = ?)
                         or  (    rodet.ro_start    = ?
                              and rodet.ro_end      = ?)
                         or  (    ro_det.ro_start   = ?
                              and ro_det.ro_end     = ?)
                         or  ( (   ro_det.ro_start >= rodet.ro_start
                                or rodet.ro_start   = ?)
                                and (   ro_det.ro_start <= rodet.ro_end
                                     or rodet.ro_end     = ?
                                     or ro_det.ro_start  = ?))
                         or  ( (        ro_det.ro_start <= rodet.ro_end
                                     or rodet.ro_end     = ?)
                         and (   ro_det.ro_end          >= rodet.ro_start
                              or ro_det.ro_end           = ?
                              or rodet.ro_start          = ?))):

                  conflicts = true.
                  leave.
               end.   /* for each rodet... */
            end.     /*  if ro_start <> ?...*/

            if conflicts = true
            then do:
               err_msg = 122.  /* DATE RANGES MAY NOT OVERLAP */
               undo ecd2-loop2, leave.
            end.  /* if conflicts */

            /*UPDATE REST OF RECORD*/
            assign
               ro_desc         = ecd2_desc
               ro_mch          = ecd2_mch
               ro_mch_op       = ecd2_mch_op
               ro_men_mch      = ecd2_men_mch
               ro_run          = ecd2_run
               ro_setup        = ecd2_setup
               ro_setup_men    = ecd2_setup_men
               ro_std_op       = ecd2_std_op
               ro_sub_cost     = ecd2_sub_cost
               ro_tool         = ecd2_tool
               ro_vend         = ecd2_vend
               ro_wkctr        = ecd2_wkctr
               ro_milestone    = ecd2_milestone
               ro_tran_qty     = ecd2_tran_qty
               ro_sub_lead     = ecd2_sub_lead
               ro_queue        = ecd2_queue
               ro_wait         = ecd2_wait
               ro_move         = ecd2_move
               ro_inv_value    = ecd2_inv_value
               ro_mv_nxt_op    = ecd2_mv_nxt_op
               ro_wipmtl_part  = ecd2_wipmtl_part
               ro_po_nbr       = ecd2_po_nbr
               ro_po_line      = ecd2_po_line
               ro_auto_lbr     = ecd2_auto_lbr
               ro_yield_pct    = ecd2_yield_pct
               ro_cmtindx      = ecd2_cmtindx.

         end. /* IF substring(ecm_doc_type = 3...*/

         err_msg = 0.

         if last-of(ecd2_routing)
         then do:
            display
               stream prt
               (getTermLabel("ROUTING_COMPLETE", 38) + ": " + ecd2_routing)
               @ msg
            with frame c STREAM-IO /*GUI*/ .
            down stream prt with frame c.
         end. /* LAST-OF(ecd2_routing)...  */

      end. /* FOR EACH ecd2_det*/

      if err_msg <> 0
      then do:
         /* PRINT ROUTING AND ERROR# */
         display
            stream prt
            (l_msgdesc[3] +  " " + string(sv-op)) @ msg
         with frame c STREAM-IO /*GUI*/ .
         down stream prt with frame c.

         run print-error-description.

         undo begin-changes, leave begin-changes.
      end.  /* err_msg <> 0... */

      ecd4-loop2:
      for each ecd4_det
         fields(ecd4_attribute ecd4_cmtindx ecd4_nbr ecd4_op ecd4_part
                ecd4_property ecd4_propertyum ecd4_routing ecd4_sequence
                ecd4_spec_det ecd4_testmthd ecd4__qadc01)
         no-lock
         where ecd4_nbr = ecm_mstr.ecm_nbr
         use-index ecd4_nbr_specid
         break by ecd4_nbr
               by ecd4_part
               by ecd4_routing
               by ecd4_op
               by ecd4_sequence with frame c:

         assign
            err_msg     = 1
            sv-op       = ecd4_op
            sv-sequence = ecd4_sequence.

         
/*GUI*/ {mfguichk.i  &warn=false &stream="(prt)"} /*Replace mfrpchk*/


         if first-of(ecd4_routing)
         then do with frame c:
            /* START ITEM SPEC: ITEM: # ROUTING: # */
            {pxmsg.i &MSGNUM   =4181
                     &MSGBUFFER=l_start_is
                     &MSGARG1  =ecd4_part
                     &MSGARG2  =ecd4_routing}

            display
               stream prt
               l_start_is @ msg
            with frame c STREAM-IO /*GUI*/ .
            down stream prt with frame c.
         end.

         if effdate = ?
         then do:
            /* EFFECTIVE DATE REQUIRED */
            err_msg = 8112.
            undo ecd4-loop2, leave.
         end.

         /*DEACTIVATE EXISTING RECORD*/
         find first ipd_det exclusive-lock
            where ipd_routing   = ecd4_routing
              and ipd_part      = ecd4_part
              and ipd_test      = ecd4_sequence
              and ipd_op        = ecd4_op
              and (   ipd_start < effdate
                   or ipd_start = ?)
              and (   ipd_end   > effdate
                   or ipd_end   = ?)
         no-error.
         if available ipd_det
         then do:
            assign
               ipd_end  = effdate - 1
               oldrecid = recid(ipd_det).

            /* SINCE THERE ARE NO DATA BASE FIELDS IN IPD_DET FOR  */
            /* START_PCO NUMBER AND END_PCO_NUMBER THESE VALUES    */
            /* WILL BE STORED IN QAD_WKFL                          */
            find qad_wkfl exclusive-lock
               where qad_key1 = "IPD-PCO-DATA"
                 and qad_key2 = (ipd_part + '::' + ipd_routing + '::' +
                                  string(ipd_op) + '::' + ipd_test + '::' +
                                  if ipd_start <> ?
                                  then
                                     string(ipd_start)
                                  else
                                     "")
            no-error.

            if not available qad_wkfl
            then do:
               create qad_wkfl.
               assign
                  qad_key1 = "IPD-PCO-DATA"
                  qad_key2 = (ipd_part + '::' + ipd_routing + '::' +
                              string(ipd_op) + '::' + ipd_test + '::' +
                              if ipd_start <> ?
                              then
                                 string(ipd_start)
                              else
                                 "").
            end.  /* IF NOT AVAILABLE... */

            /* END_PCO_NBR STORED IN QAD_CHARFLD[2] */
            qad_charfld[2] = ecm_nbr.

         end.  /* IF AVAILABLE IPD_DET... */
         else
            oldrecid = ?.

         /*ADD NEW AND MODIFIED RECORDS*/
         if substring(ecm_mstr.ecm_doc_type,3) <> "R"
            and ecd4__qadc01 <> "yes"
         then do:

            /*CHECK FOR DUPLICATE ITEM SPEC RECORD*/
            if can-find (ipd_det
                            where ipd_routing = ecd4_routing
                              and ipd_part    = ecd4_part
                              and ipd_test    = ecd4_sequence
                              and ipd_op      = ecd4_op
                              and ipd_start   = effdate)
            then do:
               /* DUPLICATE ENTRY FOR THIS DATE */
               err_msg = 5406.
               undo ecd4-loop2, leave.
            end.

            /*CREATE NEW RECORD*/
            if oldrecid <> ?
            then do:
               for first ipd_det
                  fields(ipd_attribute ipd_cmtindx ipd_end ipd_include
                         ipd_label ipd_nbr ipd_op ipd_part ipd_routing
                         ipd_start ipd_test ipd_testmthd ipd_tol
                         ipd_tol_type ipd_user1 ipd_user2 ipd__chr01
                         ipd__chr02 ipd__chr03 ipd__chr04 ipd__chr05
                         ipd__dec01 ipd__dec02)
                  where recid(ipd_det) = oldrecid
                  no-lock:
               end. /* FOR FIRST ipd_det */

               display
                  stream hf
                  ipd_det
               with frame hf1 STREAM-IO /*GUI*/ .
            end.  /* if oldrecid <> ?... */
            else do:
               display
                  stream hf
                  ecd4_routing
                  ecd4_op
               with frame hf1 STREAM-IO /*GUI*/ .
            end.   /* ELSE DO */

            display
               stream hf
               effdate @ ps_start
               ecm_mstr.ecm_nbr
            with frame hf1 STREAM-IO /*GUI*/ .

            create ipd_det.
            assign
               ipd_part    = ecd4_part
               ipd_routing = ecd4_routing
               ipd_op      = ecd4_op
               ipd_test    = ecd4_sequence
               ipd_start   = effdate.

            if recid(ipd_det) = -1 then .

            find qad_wkfl exclusive-lock
               where qad_key1 = "IPD-PCO-DATA"
                 and qad_key2 = (ipd_part + '::' + ipd_routing + '::' +
                                 string(ipd_op) + '::' + ipd_test + '::' +
                                 if ipd_start <> ?
                                 then
                                    string(ipd_start)
                                 else
                                    "")
            no-error.

            if not available qad_wkfl
            then do:
               create qad_wkfl.
               assign
                  qad_key1 = "IPD-PCO-DATA"
                  qad_key2 = (ipd_part + '::' + ipd_routing + '::' +
                              string(ipd_op) + '::' + ipd_test + '::' +
                              if ipd_start <> ?
                              then
                                 string(ipd_start)
                              else
                                 "").
            end. /* IF NOT AVAILABLE... */

            /* START_PCO_NBR STORED IN QAD_CHARFLD[1] */
            /* END_PCO_NBR STORED IN QAD_CHARFLD[2]   */
            assign
               qad_charfld[1] = ecm_nbr
               qad_charfld[2] = "".

            /*FIND END DATE FOR NEW RECORD*/
            do for ipddet:
               for first ipddet
                  fields(ipd_attribute ipd_cmtindx ipd_end ipd_include
                         ipd_label ipd_nbr ipd_op ipd_part ipd_routing
                         ipd_start ipd_test ipd_testmthd ipd_tol
                         ipd_tol_type ipd_user1 ipd_user2 ipd__chr01
                         ipd__chr02 ipd__chr03 ipd__chr04 ipd__chr05
                         ipd__dec01 ipd__dec02)
                  where ipddet.ipd_part    = ipd_det.ipd_part
                    and ipddet.ipd_routing = ipd_det.ipd_routing
                    and ipddet.ipd_op      = ipd_det.ipd_op
                    and ipddet.ipd_test    = ipd_det.ipd_test
                    and (ipddet.ipd_start  > ipd_det.ipd_start
                    and ro_start <> ?)
                  no-lock:
               end. /* FOR FIRST ipddet */

               if available ipddet
               then
                  ipd_det.ipd_end = ipddet.ipd_start - 1.
               else
                  ipd_det.ipd_end = ?.

               find first ipddet
                  where ipddet.ipd_part    = ipd_det.ipd_part
                    and ipddet.ipd_routing = ipd_det.ipd_routing
                    and ipddet.ipd_op      = ipd_det.ipd_op
                    and ipddet.ipd_test    = ipd_det.ipd_test
                    and (   ipd_start      < ipd_det.ipd_start
                         or ipd_start      = ?)
               exclusive-lock no-error.

               if available ipddet
                  and (   ipddet.ipd_end  = ?
                       or ipddet.ipd_end >= ipd_det.ipd_start)
               then
                  ipddet.ipd_end = ipd_det.ipd_start - 1.
            end.  /* do for ipddet... */

            if (    ipd_det.ipd_start  <> ?
                and ipd_det.ipd_end    <> ?
                and (ipd_det.ipd_start <= ipd_det.ipd_end))
            then do:
               conflicts = false.

               for each ipddet
                  fields(ipd_attribute ipd_cmtindx ipd_end ipd_include
                         ipd_label ipd_nbr ipd_op ipd_part ipd_routing
                         ipd_start ipd_test ipd_testmthd ipd_tol ipd_tol_type
                         ipd_user1 ipd_user2 ipd__chr01 ipd__chr02 ipd__chr03
                         ipd__chr04 ipd__chr05 ipd__dec01 ipd__dec02)
                  no-lock
                  where ipddet.ipd_part    = ipd_det.ipd_part
                    and ipddet.ipd_routing = ipd_det.ipd_routing
                    and ipddet.ipd_op      = ipd_det.ipd_op
                    and ipddet.ipd_test    = ipd_det.ipd_test
                    and recid(ipd_det)     <> recid(ipddet)
                    and ( (    ipddet.ipd_end     = ?
                           and ipd_det.ipd_end    = ?)
                     or   (    ipddet.ipd_start   = ?
                           and ipd_det.ipd_start  = ?)
                     or   (    ipddet.ipd_start   = ?
                           and ipddet.ipd_end     = ?)
                     or   (    ipd_det.ipd_start  = ?
                           and ipd_det.ipd_end    = ?)
                     or   ( (ipd_det.ipd_start   >= ipddet.ipd_start
                              or ipddet.ipd_start = ?)
                    and   (   ipd_det.ipd_start  <= ipddet.ipd_end
                           or ipddet.ipd_end      = ?
                           or ipd_det.ipd_start   = ?))
                     or ( (    ipd_det.ipd_start <= ipddet.ipd_end
                            or ipddet.ipd_end     = ?)
                    and   (   ipd_det.ipd_end    >= ipddet.ipd_start
                           or ipd_det.ipd_end     = ?
                           or ipddet.ipd_start    = ?))):

                  conflicts = true.
                  leave.
               end.   /* for each ipddet */
            end.     /* if ipd_det.ipd_start <> ?...*/

            if conflicts = true
            then do:
               err_msg = 122.
               undo ecd4-loop2, leave.
            end.  /* if conflicts */

            /*UPDATE REST OF RECORD*/
            assign
               ipd_op                = ecd4_op
               ipd_start             = effdate
               ipd_det.ipd_routing   = ecd4_routing
               ipd_det.ipd_attribute = ecd4_attribute
               ipd_det.ipd_cmtindx   = ecd4_cmtindx
               ipd_det.ipd_label     = ecd4_property
               ipd_det.ipd_test      = ecd4_sequence
               ipd_det.ipd_part      = ecd4_part
               ipd_det.ipd_testmthd  = ecd4_testmthd
               ipd_det.ipd_tol       = ecd4_spec_det
               ipd_det.ipd_tol_type  = ecd4_propertyum.

         end. /* if substring(ecm_mstr.ecm_doc_type,3) <> "R"... */

         err_msg = 0.

         if last-of(ecd4_routing)
         then do:
            /* START ITEM SPEC: ITEM: # ROUTING: # */
            {pxmsg.i &MSGNUM   =4182
                     &MSGBUFFER=l_is_complete
                     &MSGARG1  =ecd4_part
                     &MSGARG2  =ecd4_routing}

            display
               stream prt
               l_is_complete @ msg
            with frame c STREAM-IO /*GUI*/ .
            down stream prt with frame c.
         end.  /* if last-of(ecd4_routing)... */

      end. /*FOR EACH ecd4_det*/

      if err_msg <> 0
      then do:
         /* PRINT ITEM SPEC AND ERROR# */
         display
            stream prt
            (l_msgdesc[3] + " " + string(sv-op) + "  " +
             getTermLabel("TEST_SEQUENCE", 17) + " " + sv-sequence) @ msg
         with frame c STREAM-IO /*GUI*/ .
         down stream prt with frame c.

         run print-error-description.

         undo begin-changes, leave begin-changes.
      end.  /* err_msg <> 0... */

   end.  /* do (begin-changes) */

   if err_msg = 0
   then do:

      /* UPDATE IN_MSTR FOR MRP ALL PRODUCT STRUCTURE PARENT ITEMS    */
      /* AFFECTED BY THIS PCO HAVE BEEN STORED IN TEMP-TABLE WK-TABLE */

      for each wk-table exclusive-lock use-index wk-par:

         for first pt_mstr
            fields(pt_batch pt_bom_code pt_formula pt_part pt_pm_code
                   pt_status pt_um)
            where pt_part     = wk-par
              and pt_bom_code = ""
              and pt_pm_code  <> "P"
              and pt_pm_code  <> "D"
            no-lock:
         end. /* FOR FIRST pt_mstr */

         if available pt_mstr
         then do:
            for each in_mstr
               exclusive-lock
               where in_part = pt_part
                 and not can-find(ptp_det
                                     where ptp_part = in_part
                                       and ptp_site = in_site):
               if wk-new-component-added = yes
               then
                  assign
                     in_level = 99999
                     in_mrp   = yes.
               else
                  in_mrp = yes.
            end.  /* for each in_mstr... */
         end.      /* if available pt_mstr... */

         for each pt_mstr
            fields(pt_batch pt_bom_code pt_formula pt_part pt_pm_code
                   pt_status pt_um)
            no-lock
            where pt_bom_code = wk-par
              and pt_pm_code  <> "P"
              and pt_pm_code  <> "D":

            for each in_mstr
               exclusive-lock
               where in_part = pt_part
                 and not can-find(ptp_det
                                     where ptp_part = in_part
                                       and ptp_site = in_site):
               if wk-new-component-added = yes
               then
                  assign
                     in_level = 99999
                     in_mrp   = yes.
               else
                  in_mrp = yes.
            end. /* FOR EACH in_mstr... */
         end. /* FOR EACH pt_mstr... */

         for each ptp_det
            fields(ptp_bom_code ptp_part ptp_pm_code ptp_site)
            where ptp_part     = wk-par
              and ptp_bom_code = ""
              and ptp_pm_code  <> "P"
              and ptp_pm_code  <> "D":

            find in_mstr exclusive-lock
               where in_part = ptp_part
                 and in_site = ptp_site
            no-error.
            if available in_mstr
            then do:
               if wk-new-component-added = yes
               then
                  assign
                     in_level = 99999
                     in_mrp   = yes.
               else
                  in_mrp = yes.
            end. /* IF AVAILABLE in_mstr */
         end.  /* FOR EACH ptp_det... */

         for each ptp_det
            fields(ptp_bom_code ptp_part ptp_pm_code ptp_site)
            where ptp_bom_code = wk-par
              and ptp_pm_code  <> "P"
              and ptp_pm_code  <> "D":

            find in_mstr exclusive-lock
               where in_part = ptp_part
                 and in_site = ptp_site
            no-error.
            if available in_mstr
            then do:
               if wk-new-component-added = yes
               then
                  assign
                     in_level = 99999
                     in_mrp   = yes.
               else
                  in_mrp = yes.
            end. /* IF AVAILABLE in_mstr */
         end. /* for each ptp_det... */

         delete wk-table.
      end. /* FOR EACH wk-table... */

      /* UPDATE ECM EFFECTIVE DATES */
      find ecm1 exclusive-lock
         where recid(ecm1) = recid(ecm_mstr).
      assign
         ecm1.ecm_eff_date     = effdate
         ecm1.ecm_selected_eff = ?.

      /* PRINT INCORPORATION COMPLETE MESSAGE */
      display
         stream prt
         "** " + l_incorp_success + " **" @ msg WITH STREAM-IO /*GUI*/ .
      down stream prt 2 with frame c.

   end.  /* if err_msg = 0... */

   /* IF ERRORS FOUND, PRINT INCORP UNSUCCESSFUL MESSAGE */
   else do:
      display
         stream prt
         l_incorp_unsuccess @ msg WITH STREAM-IO /*GUI*/ .
      down stream prt 2 with frame c.
      undo mainloop, next mainloop.
   end.  /* err_msg <> 0 */

end. /*for each ecm_mstr*/

output stream hf close.

/* ---------------------------------------------------------- */
/*       INTERNAL PROCEDURES                                  */
/* ---------------------------------------------------------- */

PROCEDURE print-error-description:

   /* PRINT ERROR DESCRIPTION */
   for first msg_mstr
      fields(msg_desc msg_lang msg_nbr)
      where msg_lang = global_user_lang
        and msg_nbr  = err_msg
      no-lock:
   end. /* FOR FIRST msg_mstr */

   if available msg_mstr
   then do:
      if err_msg <> 1
      then
         display
            stream prt
            ("  " + substring(msg_desc,1,58)) @ msg
         with frame c STREAM-IO /*GUI*/ .
      else
         display
            stream prt
            l_msgdesc[1] @ msg
         with frame c STREAM-IO /*GUI*/ .

      down stream prt with frame c.
   end.  /* IF AVAILABLE msg_mstr... */

END PROCEDURE. /* PROCEDURE print-error-description */
